package com.tvein.sanguo.tool.view
{
	//flash
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	//pureMVC
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.mediator.FlashMediator;
	//custom
	import com.tvein.sanguo.tool.common.GameConstants;
	import com.tvein.sanguo.tool.model.SystemProxy;
	import com.tvein.sanguo.Tool;
	import com.tvein.sanguo.swc.tool.ToolShell;
//
	public class ToolMediator extends FlashMediator
	{
		static public const NAME : String = "ToolMediator";
		
		public function ToolMediator(viewComponent:Object)
		{
			super(NAME, viewComponent);
		}
		
		public function get tool() : Tool
		{
			return viewComponent as Tool;
		}
		
		//Custom
		private var systemData:SystemProxy;
		public var toolShell:ToolShell;
		
		override public function onRegister() : void
		{
			systemData = facade.retrieveProxy(SystemProxy.NAME) as SystemProxy;
			
			tool.visible = false;
			
			toolShell = new ToolShell();
			
			tool.addChild(toolShell);
			
			var params:Object = new Object();
			params.Volume = systemData.effectVol;
			toolShell.console("setEffect", params);
			
			toolShell.addEventListener("ToolShell", _handleEvents);
		}
		
		private function _handleEvents(evt:Object):void
		{
			if (evt.cmd[0] == "-tool" && evt.cmd[1][0] == "advice")
			{
				routeNotification(GameConstants.MODULE_INVOKE, ["-init", ["advice"]], null, GameConstants.MODULE_PROMPT + "/*");
			}
			else
			{
				routeNotification(GameConstants.MODULE_INVOKE, evt.cmd, null, GameConstants.MODULE_ACTION + "/*");
			}
		}
	}
}